/*(

var xb, cp, doc, root;
cp = AbstractControlPlugin.new;
cp.setValue("test", 4545);

doc = DOMDocument.new;
xb = XMLNodeBuilder.new;

root = doc.createElement('ripple');
doc.appendChild(root);

xb.setParent(root);

xb.forControlPlugin(cp);

doc.format

)*/



XMLNodeBuilder{
	var parent, thisNode, object, document;
		
	getNode{
		^thisNode
	}
	
	setDocument{|doc|
		document = doc;
	}
	
	setParent{|parentArg|
		parent = parentArg;
		document = parent.getOwnerDocument;
	}
	
	forControlPlugin{|obj|
		var vals, class, nodeInHand;
				
		class = obj.class;
		vals = obj.getVals;	

		thisNode = document.createElement("plugin");
		parent.appendChild(thisNode);
	
		nodeInHand = document.createElement("pluginClass");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(class.asString)
		);
		
		vals.keysValuesDo{|key, val|
			"looping".postln;	
			thisNode.appendChild(
				document.createElement("setting")
					.setAttribute( "name" , key.asString )
					.setAttribute( "value" , val.asString );
			)
		}
	}
	
	forRipple{|obj|
		thisNode = document.createElement("ripple");
		document.appendChild(thisNode);
	}
	
	forPage{|obj|
		thisNode = document.createElement("page");
		parent.appendChild(thisNode);
	}
	
	forVoice{|obj|
		var vals, class, nodeInHand;
				

		thisNode = document.createElement("voice");
		parent.appendChild(thisNode);
	
		nodeInHand = document.createElement("name");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getName)
		);
		
		nodeInHand = document.createElement("audioFile");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getAudioFilePath)
		);
		
		nodeInHand = document.createElement("synthType");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getSynthType.asString)
		);
		
		nodeInHand = document.createElement("midiChannel");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getMidiChannel.asString)
		);
		
		nodeInHand = document.createElement("polyPhonic");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getPoly.asString)
		);
		
		

	}
	
	forControl{|obj|
	
		var vals, class, nodeInHand;
		
		thisNode = document.createElement("control");	
		parent.appendChild(thisNode);
		
		nodeInHand = document.createElement("name");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getName.asString)
		);
		
		nodeInHand = document.createElement("value");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getOneToZeroValue.asString)
		);
		
		nodeInHand = document.createElement("rand");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getRandAmt.asString)
		);
		
	}
	
	forConnectionManager{|obj|
		thisNode = document.createElement("connections");
		parent.appendChild(thisNode);	
	}	
	
	forConnection{|obj|
	
		var vals, class, nodeInHand;
		
		thisNode = document.createElement("connection");	
		parent.appendChild(thisNode);
		
		nodeInHand = document.createElement("connectionClass");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.class.asString)
		);
		
		nodeInHand = document.createElement("sourceName");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getSourceName.asString)
		);
		
		nodeInHand = document.createElement("targetName");
		thisNode.appendChild(nodeInHand);
		
		nodeInHand.appendChild(
			document.createTextNode(obj.getTargetName.asString)
		);
		
		
	}

	
}